//
//  ViewController.m
//  更丰富的用户界面
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置doSomething按钮的背景(需要对图片进行拉伸设置）
    // 1. 代码方式
    //    // 代码实现设置按钮的背景图片
    //    UIImage *img1 = [UIImage imageNamed:@"whiteButton"];
    //    UIImage *img2 = [UIImage imageNamed:@"blueButton"];
    //
    //    // 创建拉伸的图片 (左右各留12像素不拉伸)
    //    UIEdgeInsets insets = UIEdgeInsetsMake(0, 12, 0, 12);// 上左下右
    //    UIImage *img3 = [img1 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    //    UIImage *img4 = [img2 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    //
    //    [self.doSomethingBtn setBackgroundImage:img3 forState:UIControlStateNormal];
    //    [self.doSomethingBtn setBackgroundImage:img4 forState:UIControlStateHighlighted];
    
    // 2. 删除原来拖到项目中的图片，重新拉图片放在Assets.scassets中,用Assets.scassets管理图片。
    //设置一下需要拉伸的图片的切片,图片被使用的时候会自动拉伸
}

// * sender 是当前触发这个方法的对象



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)switchChanged:(UISwitch *)sender {
    
    BOOL open=sender.on;
    
    //设置状态，并设置是否带上动画
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:YES];
}

- (IBAction)segementedChanged:(UISegmentedControl *)sender {
    if (sender.selectedSegmentIndex==0) {
        self.leftSwitch.hidden=NO;
        self.rightSwitch.hidden=NO;
        self.doSomethingBtn.hidden=YES; 
    }
    else{
        self.leftSwitch.hidden=YES;
        self.rightSwitch.hidden=YES;
        self.doSomethingBtn.hidden=NO;
    }
}

- (IBAction)doSomething:(id)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"你确定么？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"是的，确定!" otherButtonTitles:nil, nil];
    [sheet showInView:self.view];}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.destructiveButtonIndex) {
        NSString *nameinfo = [NSString stringWithFormat:@"%@  放轻松一切运行正常",self.nameTextField.text];
        UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"某些事项被执行了" message:nameinfo delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [view show];
    }
}

- (IBAction)sliderChanged:(UISlider *)sender {
    int value=sender.value;
    self.label.text=[NSString stringWithFormat:@"%i",value];
}


- (IBAction)backPre:(id)sender {
    //第一种方法，结束编辑
    [self.view endEditing:YES];
    //    //第二种取消第一响应者
    // [self.nameTextField resignFirstResponder];
    // [self.numberTextField resignFirstResponder];
    

}
@end
